package io.renren.common.utils;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Singer create by singer email:313402703@qq.com
 * @projectName singer-management-platform
 * @Description: 通过IP拿到地址的工具
 * @date 2019-08-21
 */
@Slf4j
public class IpAddressUtil {


    public static void main(String[] args) {
        String url = "http://ip.360.cn/IPQuery/ipquery";

        Map<String,String> paramMap = new HashMap<>();

        paramMap.putIfAbsent("ip","118.112.72.171");

        String request = HttpTookit.postRequest(url, paramMap);

        System.out.println(request);

        System.out.println(queryAddressByIpFrom360("118.112.72.171",url));


    }



    /**
      *
      * @description: 从360的IP分享计划接口拿到详细地理位置
      * @auther: create by singer - 王 浩 email:313402703@qq.com
      * @date 2019-08-21
      * @param ip IP地址
      * @param url 请求url地址
      * @return String
      */
    public static String queryAddressByIpFrom360(String ip,String url){
        Map<String,String> paramMap = new HashMap<>();
        paramMap.putIfAbsent("ip",ip);

        String data = HttpTookit.postRequest(url, paramMap);

        if(CheckParam.isNull(data)) return null;

        AddressFromIPVo addressFromIPVo = JSON.parseObject(data, AddressFromIPVo.class);

        return addressFromIPVo.getData().trim();
    }

}
